package com.fowo.api.model.sales.withdraw;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fowo.api.entity.SalesWithdraw;
import com.fowo.api.mapper.SalesWithdrawMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
@DS("ds24")
public class SalesWithdrawBatchCancellationImpl extends ServiceImpl<SalesWithdrawMapper, SalesWithdraw> implements SalesWithdrawBatchCancellationAction{

    @Resource
    SalesWithdrawMapper salesWithdrawMapper;

    @Override
    public void run(List<Long> idList) throws Exception {
        for(Long id : idList){
            SalesWithdraw salesWithdraw = salesWithdrawMapper
                    .selectOne(Wrappers.lambdaQuery(SalesWithdraw.class).
                            eq(SalesWithdraw::getStatus, "2")
                            .eq(SalesWithdraw::getId, id));
            if(salesWithdraw==null){
                new LambdaUpdateChainWrapper<>(baseMapper)
                        .set(SalesWithdraw::getStatus, "2")
                        .eq(SalesWithdraw::getId, id)
                        .update();
            }
        }
    }
}
